<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<!-- 
		Replace path to template, title, header and body
		with actual data.
	 -->
<ui:composition template="/templates/template.xhtml">
	<ui:define name="pageTitle">Vendas</ui:define>
	<ui:define name="pageHeader">Registro de Vendas</ui:define>
	<ui:define name="body">
		<h:form id="idBuscaProduto">
		<h:message/>
			<h:panelGrid columns="2">
				<h:outputLabel value="Cliente:" />
				<h:selectOneMenu value="#{registroVendasBean.clienteSelecionado}">
				<f:selectItem itemLabel="Selecione um cliente:"/>
					<f:selectItems value="#{registroVendasBean.clienteSelect}" />
					<f:ajax event="change" render="idClienteSelecionado" />
				</h:selectOneMenu>
				
				<h:outputLabel value="Produto:" />
				<h:panelGroup>
					<h:inputText value="#{registroVendasBean.produtoSelecionado.descricao}" />
					<h:commandButton value="Pesquisar" action="#{registroVendasBean.buscarProduto}" >
					<f:ajax event="change"  render="idValorTotal"/>
					</h:commandButton>
				</h:panelGroup>	
				
				<h:outputLabel value="Id do Cliente" />
				<h:outputText id="idClienteSelecionado" value="#{registroVendasBean.clienteSelecionado.id}"/>	
				
				<h:dataTable value="#{registroVendasBean.carrinhoCompras}" rendered="#{not empty registroVendasBean.carrinhoCompras}" var="produto" border="1" >
				<f:facet name="header"> Listagem Carrinho de Compras</f:facet>
				<h:column>
				<f:facet name="header">Descrição</f:facet>
				#{produto.descricao}
				</h:column>			
				<h:column>
					<f:facet name="header">Ações</f:facet>
					<h:commandLink action="#{registroVendasBean.excluirProdutoCarrinho}"
						onclick="if (!confirm('Deseja Realmente excluir esse produto #{produto.descricao} do carrinho?')) return false;">
						<h:graphicImage library="imagens" name="remove-icon.png" />
						<f:setPropertyActionListener
							target="#{registroVendasBean.produtoSelecionado}" value="#{produto}" />
					</h:commandLink>
				</h:column>
				</h:dataTable>
				<h:panelGroup>
				<h:outputLabel value="Subtotal "/>
				<h:outputText id="idValorTotal" value="#{registroVendasBean.valorTotal}" >
				<f:convertNumber currencyCode="BRL" type="currency"/>
				</h:outputText>
				</h:panelGroup>
				<h:commandButton value="Finalizar Venda" action="#{registroVendasBean.finalizarVenda}"/>
			</h:panelGrid>
		</h:form>
	</ui:define>
</ui:composition>

</html>